/*
 * TCSS 360 - Winter 2014
 * TESK Software
 */
package view;

import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.JLabel;
import java.awt.Font;

import javax.swing.ImageIcon;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import java.awt.BorderLayout;
import java.util.ArrayList;


/**
 * Displays the conferences that are currently available.
 *  
 * @author Kon.
 * @version 3/12/14
 */
@SuppressWarnings("serial")
public class CurrentConference extends JPanel {
	/** Table that contains the conferences and dates.*/
	private JTable table;
	
	/** The frame associated with the panel. */
	private MainFrame my_frame;

	/**
	 * Constructs the current conference panel.
	 * @param the_frame the frame to associate the panel with
	 */
	public CurrentConference(MainFrame the_frame) {
		super();
		my_frame = the_frame;
	}
	
	/**
	 * Setup the panel.
	 * @author Kon.
	 */
	public void setup(){
		setBackground(Color.WHITE);
		setLayout(new GridLayout(2, 1, 0, 0));
		this.setPreferredSize(new Dimension(500,400));
		init();
		
	}
	
	/**
	 * Adds the components of the Panel to the panel.
	 * @author Kon, Emily, Thang.
	 */
	private void init(){
		JPanel topPanel = new JPanel();
		topPanel.setBackground(Color.WHITE);
		add(topPanel);
		
		table = new JTable();
		table.setEnabled(false);
		table.setFont(new Font("Tahoma", Font.PLAIN, 15));
		
		ArrayList<String> conferences = my_frame.db.getConferences();
		String[][] conferenceList = new String[conferences.size()][conferences.size()];
		for (int i = 0; i < conferences.size(); i++) {
			conferenceList[i][0] = conferences.get(i);
			conferenceList[i][1] = "12/5/2015";
		}
		table.setModel(new DefaultTableModel(
			conferenceList,
			new String[] {
				"New column", "New column"
			}
		) {
			boolean[] columnEditables = new boolean[] {
				false, true
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		table.getColumnModel().getColumn(0).setResizable(false);
		table.getColumnModel().getColumn(0).setPreferredWidth(171);
		table.getColumnModel().getColumn(1).setPreferredWidth(175);
		topPanel.setLayout(new BorderLayout(0, 0));
		
		JPanel northPanel = new JPanel();
		northPanel.setBackground(Color.LIGHT_GRAY);
		topPanel.add(northPanel, BorderLayout.NORTH);
		northPanel.setLayout(new GridLayout(0, 2, 0, 0));
		
		JLabel lblNewLabel_1 = new JLabel("Current Conference    ");
		lblNewLabel_1.setFont(new Font("Toledo", Font.PLAIN, 18));
		northPanel.add(lblNewLabel_1);
		
		JLabel lblNewLabel = new JLabel("     Deadline");
		lblNewLabel.setFont(new Font("Toledo", Font.PLAIN, 18));
		northPanel.add(lblNewLabel);
		topPanel.add(table, BorderLayout.CENTER);
		
		//2nd panel of 2nd grid ***********************************************************
		JPanel botPanel = new JPanel();
		add(botPanel);
		botPanel.setLayout(new BorderLayout(0, 0));
		botPanel.setBackground(Color.white);
		
		JPanel buttonPanel = new JPanel();
		botPanel.add(buttonPanel, BorderLayout.SOUTH);
		
		//********** image label ************************
		ImageIcon icon = new ImageIcon(getClass().getResource("/uw1.jpg"));
		final JLabel pic = new JLabel();
		pic.setIcon(icon);
		
		
//		final JLabel pic = new JLabel();
//		pic.setIcon(new ImageIcon("..\\Conference System\\src\\uw1.jpg"));
		botPanel.add(pic, BorderLayout.CENTER);
		
		//********************************
		JPanel empty = new JPanel();
		empty.setBackground(Color.white);
		empty.setPreferredSize(new Dimension(100,100));
		botPanel.add(empty, BorderLayout.WEST);
		
	}
}
